package com.csust.common.hdfs;

import com.csust.common.pojo.SystemConstants;

import static com.csust.common.pojo.SystemConstants.*;
/***
 * 生成hdfs operator的工厂
 * @author yhm
 * @date 2021/10/30
 * @descripe 使用工厂模式，可以方便的调用三个用户的权限。
 * 如，HdfsOp hdfsOp = HdfsOpFactory.getHdfsOp(SystemConstants.USER2_PRINCIPAL);
 */
public class HdfsOpFactory {
    
    public static HdfsOp getHdfsOp(String userPrincipal) {
        String path2UseKeyTab = null;
        String userRootDir = null;
        if (USER2_PRINCIPAL.equals(userPrincipal)) {
            path2UseKeyTab = PATH_TO_USER2_KEYTAB;
            userRootDir = USER2_ROOT_DIR;
        } else if (USER3_PRINCIPAL.equals(userPrincipal)) {
            path2UseKeyTab = PATH_TO_USER3_KEYTAB;
            userRootDir = USER3_ROOT_DIR;
        } else if (USER4_PRINCIPAL.equals(userPrincipal)) {
            path2UseKeyTab = PATH_TO_USER4_KEYTAB;
            userRootDir = USER4_ROOT_DIR;
        }
        try {
            return new HdfsOp(userPrincipal, path2UseKeyTab, SystemConstants.NAMENODE_RPC_ADDRESS_NN1, userRootDir);
        } catch (Exception e) {
            e.printStackTrace();
            return new HdfsOp(userPrincipal, path2UseKeyTab, SystemConstants.NAMENODE_RPC_ADDRESS_NN2, userRootDir);
        }
    }
}

